#coding=utf-8
from uliweb.orm import *
import datetime
from uliweb import functions

class Menu(Model):
    """
    菜单
    """
    menuname = Field(str, verbose_name='菜单名', max_length=30, unique=True, index=True, nullable=False)
    menuurl = Field(str, verbose_name='url地址', max_length=150)
    menupid = Field(int, verbose_name='父ID')
    menuicon = Field(str, verbose_name='菜单图标', max_length=50)
    menuseq = Field(int, verbose_name='菜单排序')
    menupath = Field(str, verbose_name='菜单级别序号,父id,使用逗号分割', max_length=100)
    menutype = Field(int, verbose_name='菜单类型 1、菜单 2、功能')
    props = Field(PICKLE)

    def get_users(self):
        for role in self.menu_menuroles.all():
            for u in role.users.all():
                yield u
                
    def get_users_ids(self):
        for role in self.menu_menuroles.all():
            for u in role.users.ids():
                yield u
    
    def __unicode__(self):
        return self.name